package com.foreveross.proxyip.entity;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import com.foreveross.proxyip.infra.base.ddd.domain.BaseEntity;
import com.foreveross.proxyip.infra.cache.IBufferCacheEntity;


/**
 * The persistent class for the pi_retrieve database table.
 * 
 */
@Entity
@Table(name="pi_retrieve")
public class RetrieveIpEntity extends BaseEntity  implements IBufferCacheEntity{
	private static final long serialVersionUID = 1L;

	@GeneratedValue(generator="idGenerator") //使用uuid的生成策略
	@GenericGenerator(name="idGenerator", strategy="uuid") //这个是hibernate的注解
	@Id
	private String id;
	
	private String area;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="create_time")
	private Date createTime;

	
	private String ip;

	private Integer port;

	@Column(name="response_time")
	private Integer responseTime;

	@Column(name="retrieve_channel")
	private String retrieveChannel;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="retrieve_time")
	private Date retrieveTime;

	private Integer state;

	private String source;

	public RetrieveIpEntity() {
	}

	public String getArea() {
		return this.area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getIp() {
		return this.ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Integer getPort() {
		return this.port;
	}

	public void setPort(Integer port) {
		this.port = port;
	}

	public Integer getResponseTime() {
		return this.responseTime;
	}

	public void setResponseTime(Integer responseTime) {
		this.responseTime = responseTime;
	}

	public String getRetrieveChannel() {
		return this.retrieveChannel;
	}

	public void setRetrieveChannel(String retrieveChannel) {
		this.retrieveChannel = retrieveChannel;
	}

	public Date getRetrieveTime() {
		return this.retrieveTime;
	}

	public void setRetrieveTime(Date retrieveTime) {
		this.retrieveTime = retrieveTime;
	}

	public Integer getState() {
		return this.state;
	}

	public void setState(Integer state) {
		this.state = state;
	}
	
	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}
	
	
	/**
	 * 根据该对象属性获取一个数据库持久类对象
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	public HistoryIpEntity toHistoryIpEntity() throws IllegalAccessException, InvocationTargetException{
		HistoryIpEntity dest = new HistoryIpEntity();
		dest.setArea(area);
		dest.setCreateTime(new Date());
		dest.setIp(ip);
		dest.setPort(port);
		dest.setResponseTime(responseTime);
		dest.setRetrieveChannel(retrieveChannel);
		dest.setRetrieveTime(retrieveTime);
		dest.setState(state);
		dest.setSource(source);
		return dest;
	}
	
}